$(function () {
  $(".zhudeng1").click(function () {
    $(".zhubox2").show();
    console.log($(".zhubox2"));
  });
  $(".ji3").click(function () {
    $(".zhubox2").show().siblings().hide();
  });
  $(".zhubox2").hide();
  $(".zhubox3").hide();
  $("#zhuzhu11").click(function () {
    $.ajax({
      url: "http://jx.xuzhixiang.top/ap/api/reg.php",
      type: "get",
      data: { username: $("#zhushou").val(), password: $("#zhuduan").val() },
      success: function (data) {
        if (data.code) {
          $.ajax({
            url: "http://jx.xuzhixiang.top/ap/api/login.php",
            type: "get",
            data: {
              username: $("#zhushou").val(),
              password: $("#zhuduan").val(),
            },
            success: function (data) {
              if (data.code) {
                window.location.href = "shouye.html";
              } else {
                alert("登陆失败");
              }
            },
          });
        } else {
          alert("注册失败");
        }
      },
    });
  });
  $(".zhuzhu11").click(function () {
    $.ajax({
      url: "http://jx.xuzhixiang.top/ap/api/login.php",
      data: { username: $("#zhushou").val(), password: $("#zhuduan").val() },
      success: function (data) {
        if (data.code) {
          window.location.href = "shouye.html";
          localStorage.setItem("username", $(".zhushou").val());
          localStorage.setItem("password", $(".zhuduan").val());
          localStorage.setItem("uid", data.data.id);
          localStorage.setItem("token", data.data.token);
        } else {
          alert("登录失败");
        }
      },
    });
  });
});
